package com.example.jk.controller;


import com.example.jk.common.Result;
import com.example.jk.entity.User;
import com.example.jk.service.UserService;
import com.example.jk.util.UtilIdCar;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cjx
 * @since 2021-04-04
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserService userService;

    /**
     * 注册
     * @param user
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody  User user){
        Map<String, String> map = UtilIdCar.getBirAgeSex(user.getId_car());
        user.setSex(map.get("sexCode"));
        user.setBirthday(map.get("birthday"));
        user.setAge(Integer.parseInt(map.get("age")));
        return userService.add(user);
    }

    /**
     * 登录
     * @param user
     * @return
     */
    @GetMapping("/log")
    public Result log(User user){
        return userService.log(user);
    }

    /**
     *
     * @param user
     * @return
     */
    @GetMapping("/detail")
    public  Result detail(User user){
        return userService.dateil(user);
    }

    /**
     * 找回密码
     * @param user
     * @return
     */
    @GetMapping("/retrievePassword")
    public Result retrievePassword(User user){
        return userService.retrievePassword(user);
    }

}
